package com.example.foobar.controller;

import com.example.foobar.business.service.DyVideoService;
import com.example.foobar.entity.DyVideo;
import com.example.foobar.dao.service.DyVideoDaoService;
import com.example.foobar.vo.DyVideoQueryVo;
import lombok.extern.slf4j.Slf4j;
import com.example.foobar.param.DyVideoPageParam;
import io.geekidea.springbootplus.framework.common.controller.BaseController;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.log.annotation.Module;
import io.geekidea.springbootplus.framework.log.annotation.OperationLog;
import io.geekidea.springbootplus.framework.log.enums.OperationLogType;
import io.geekidea.springbootplus.framework.core.validator.groups.Add;
import io.geekidea.springbootplus.framework.core.validator.groups.Update;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 抖音视频内容 控制器
 *
 * @author 郑英奔
 * @since 2021-07-23
 */
@Slf4j
@RestController
@RequestMapping("/dyVideo")
@Module("foobar")
@Api(value = "抖音视频内容API", tags = {"抖音视频内容"})
public class DyVideoController extends BaseController {

    @Autowired
    private DyVideoService dyVideoService;

    /**
     * 添加抖音视频内容
     */
    @PostMapping("/add")
    @OperationLog(name = "添加抖音视频内容", type = OperationLogType.ADD)
    @ApiOperation(value = "添加抖音视频内容", response = ApiResult.class)
    public ApiResult<Boolean> addDyVideo(@Validated(Add.class) @RequestBody DyVideo dyVideo) throws Exception {
        boolean flag = dyVideoService.saveDyVideo(dyVideo);
        return ApiResult.result(flag);
    }

    /**
     * 修改抖音视频内容
     */
    @PostMapping("/update")
    @OperationLog(name = "修改抖音视频内容", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改抖音视频内容", response = ApiResult.class)
    public ApiResult<Boolean> updateDyVideo(@Validated(Update.class) @RequestBody DyVideo dyVideo) throws Exception {
        boolean flag = dyVideoService.updateDyVideo(dyVideo);
        return ApiResult.result(flag);
    }

    /**
     * 删除抖音视频内容
     */
    @PostMapping("/delete/{id}")
    @OperationLog(name = "删除抖音视频内容", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除抖音视频内容", response = ApiResult.class)
    public ApiResult<Boolean> deleteDyVideo(@PathVariable("id") Long id) throws Exception {
        boolean flag = dyVideoService.deleteDyVideo(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取抖音视频内容详情
     */
    @GetMapping("/info/{id}")
    @OperationLog(name = "抖音视频内容详情", type = OperationLogType.INFO)
    @ApiOperation(value = "抖音视频内容详情", response = DyVideo.class)
    public ApiResult<DyVideo> getDyVideo(@PathVariable("id") Long id) throws Exception {
        DyVideo dyVideo = dyVideoService.getById(id);
        return ApiResult.ok(dyVideo);
    }

    /**
     * 抖音视频内容分页列表
     */
    @PostMapping("/getPageList")
    @OperationLog(name = "抖音视频内容分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "抖音视频内容分页列表", response = DyVideo.class)
    @RequiresPermissions("sys:dy-video:page")
    public ApiResult<Paging<DyVideoQueryVo>> getDyVideoPageList(@Validated @RequestBody DyVideoPageParam dyVideoPageParam) throws Exception {
        Paging<DyVideoQueryVo> paging = dyVideoService.getDyVideoPageList(dyVideoPageParam);
        return ApiResult.ok(paging);
    }

}

